# !/bin/bash

if [ ! -d onnx ]; then
    mkdir onnx
    
    pip install huggingface_hub onnxruntime -i https://mirrors.aliyun.com/pypi/simple
    export HF_ENDPOINT=https://hf-mirror.com
    huggingface-cli download --resume-download onnx-community/YOLOv10 yolov10n.onnx --local-dir onnx
fi


if [ ! -d onnxruntime ]; then
    git clone --recursive https://github.com/Microsoft/onnxruntime.git
    pushd onnxruntime
    ./build.sh --config Release --build_shared_lib --parallel --allow_running_as_root
    popd
fi

########################################################################
script_path="${BASH_SOURCE[0]}"
# get script abs directory
while [ -h "$script_path" ]; do
    script_dir="$(cd -P "$(dirname "${script_path}")" >/dev/null 2>&1 && pwd)"
    script_path="$(readlink "$script_path")"
    [[ $script_path != /* ]] && script_path="$script_dir/$script_path"
done
script_dir="$(cd -P "$(dirname "${script_path}")" >/dev/null 2>&1 && pwd)"

project_dir=$(realpath $(dirname "${script_dir}"))
echo -e "Found project DIR_PATH: \033[32m $project_dir \033[0m"
########################################################################


if [ ! -d build ]; then
    mkdir build
fi

pushd build
cmake .. && make -j
./yolov10_cpu ../onnx/yolov10n.onnx ${project_dir}/examples/cv/detection/assets/bus.jpg
popd
